using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace EditWebSite.Logics
{
    static class GestException
    {
        internal static string ParseExceptionAutentication(System.Web.Services.Protocols.SoapException soapEx)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(soapEx.Detail.OuterXml);
            XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
            nsManager.AddNamespace("errorNS", "http://www.sardegnadoc.it/Authentication");
            XmlNode categoryNode = doc.DocumentElement.SelectSingleNode("errorNS:Error", nsManager);
            string errorNumber = categoryNode.SelectSingleNode("errorNS:ErrorNumber", nsManager).InnerText;
            string errorMessage = categoryNode.SelectSingleNode("errorNS:ErrorMessage", nsManager).InnerText;
            string errorSource = categoryNode.SelectSingleNode("errorNS:ErrorSource", nsManager).InnerText;
            return errorMessage;
        }

        internal static string ParseExceptionDatabase(System.Web.Services.Protocols.SoapException soapEx)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(soapEx.Detail.OuterXml);
            XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
            nsManager.AddNamespace("errorNS", "http://www.sardegnadoc.it/Database");
            XmlNode categoryNode = doc.DocumentElement.SelectSingleNode("errorNS:Error", nsManager);
            string errorNumber = categoryNode.SelectSingleNode("errorNS:ErrorNumber", nsManager).InnerText;
            string errorMessage = categoryNode.SelectSingleNode("errorNS:ErrorMessage", nsManager).InnerText;
            string errorSource = categoryNode.SelectSingleNode("errorNS:ErrorSource", nsManager).InnerText;
            return errorMessage;
        }
    }
}
